import React, { Component } from 'react'
import { connect } from 'react-redux'
import action from './store/acitons/home'
@connect
class Home extends Component {
  componentDidMount () {
    this.props.getBannerList()
    this.props.getProList()
  }
  render() {
    return (
      <div>
        home - { this.props.username }
        <ul>
          {
            this.props.bannerList.map(item => {
              return (
                <img src={ item.img } key = { item.bannerid } alt=""/>
              )
            })
          }
        </ul>
        <ul>
          {
            this.props.proList.map(item => {
              return (
                <li key = { item.proid }>{ item.proname }</li>
              )
            })
          }
        </ul>
      </div>
    )
  }
}

export default connect((state) => {
  return {
    bannerList: state.home.bannerList,
    proList: state.home.proList,
    username: state.user.username
  }
}, (dispatch) => {
  return {
    getBannerList () {
      dispatch(action.getBannerListAction)
    },
    getProList () {
      dispatch(action.getProListAction({ limitNum: 30 }))
    }
  }
})(Home)